package com.eclipsemail.ui.editor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

import swing2swt.layout.BorderLayout;

import com.eclipsemail.core.message.EmailMessage;

public class MailEditorPart extends EditorPart {

    public MailEditorPart() {
    }

    public static final String ID = "com.eclipsemail.ui.editor.MailEditorPart";

    private Label contents;

    private EmailMessage mail;

    @Override
    public void createPartControl(Composite parent) {
        parent.setLayout(new BorderLayout(0, 0));
        //contents = new Label(parent, SWT.NONE);
        //contents.setText(mail.getContent());

        Browser browser = new Browser(parent, SWT.NONE);
        browser.setText(mail.getContent());

        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayoutData(BorderLayout.SOUTH);

        Button btnReply = new Button(composite, SWT.NONE);
        btnReply.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // FIXME
                System.out.println("not implemented...");
            }
        });
        btnReply.setBounds(23, 0, 68, 23);
        btnReply.setText("Reply");
    }

    @Override
    public void doSave(IProgressMonitor monitor) {
    }

    @Override
    public void doSaveAs() {
    }

    @Override
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
        setSite(site);
        setInput(input);

        assert input instanceof MailEditorInput : "IEditorInput class: " + input.getClass();
        mail = ((MailEditorInput) input).getMail();
    }

    @Override
    public boolean isDirty() {
        return false;
    }

    @Override
    public boolean isSaveAsAllowed() {
        return false;
    }

    @Override
    public void setFocus() {
        if (contents != null) {
            contents.setFocus();
        }
    }
}
